package moodish.server.testing;

import java.util.LinkedList;
import moodish.comm.ServerComm;
import moodish.comm.ServerSideMessage;
import moodish.message.MessageFromClient;

/**
 * Class that implements the interface {@link #ServerComm}
 */
public class ServerCommDummyTest implements ServerComm
{
	private LinkedList<MessageFromClient>	messagesReceived	= new LinkedList<MessageFromClient>();
	@Override
	public void start()
	{

	}

	@Override
	public ServerSideMessage getNextMessage()
	{
		synchronized (messagesReceived)
		{
			while (!hasNextMessage())
			{
				try
				{
					messagesReceived.wait();
				}
				catch (InterruptedException e)
				{
				}
			}
			return messagesReceived.poll();
		}
	}

	@Override
	public boolean hasNextMessage()
	{
		return !messagesReceived.isEmpty();
	}

	@Override
	public void sendMoodishMessage(String fromNicename, String toNickname, String moodishMessage)
	{
	}

	@Override
	public void sendNewFriendship(String toNickname, String newFriendship)
	{
	}

	@Override
	public void sendNewUnfriendship(String toNickname, String unfriendship)
	{
	}

	@Override
	public void sendError(String toNickname, String error)
	{
		System.out.println("ERROR!!! - " + error);
	}
	@Override
	public void sendClientConnected(String toNickname, String connectedNickname)
	{
	}

	@Override
	public void sendClientDisconnected(String toNickname, String disconnectedNickname)
	{
	}

	@Override
	public boolean clientIsConnected(String nickname)
	{
		return false;
	}

	@Override
	public void disconnectClient(String nickname)
	{

	}
	public void addMessage(MessageFromClient message)
	{
		synchronized (messagesReceived)
		{
			messagesReceived.add(message);
			messagesReceived.notifyAll();

		}
	}
}
